<template>
  <div class="login-page">
    <div class="logo">
      <div>
        <img class="img1" src="../assets/platform.png" alt="" />
      </div>
      <div>
        <img class="img2" src="../assets/platform-name.png" alt="" />
      </div>
    </div>
    <div class="form">
      <el-form
        :model="loginForm"
        :rules="loginRules"
        ref="loginForm"
        class="loginForm"
        label-width="130px"
      >
        <el-form-item prop="username">
          <el-input
            type="person"
            v-model="loginForm.username"
            placeholder="账户"
            maxlength="30"
          >
            <template slot="prepend">
              <i class="el-icon-user" style="font-size: 18px"></i>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            type="password"
            v-model="loginForm.password"
            placeholder="密码"
            maxlength="30"
          >
            <template slot="prepend">
              <i class="el-icon-lock" style="font-size: 18px"></i>
            </template>
          </el-input>
        </el-form-item>

        <!-- <el-form-item>
          <div class="opt">
            <div>
              <el-checkbox v-model="checked" class="check"></el-checkbox>
              自动登录
            </div>
            <div class="forget">忘记密码</div>
          </div>
        </el-form-item> -->

        <el-form-item>
          <el-button
            class="submit"
            :loading="$store.state.subLoading"
            @click="submitForm"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import api from "@/api/user.js";
import util from "@/utils/auth";
export default {
  data() {
    return {
      // checked: true,
      loginForm: {
        username: "",
        password: "",
      },
      loginRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          // {
          //   pattern: /^1([3456789])\d{9}$/,
          //   message: "请输入正确的手机号",
          //   trigger: "blur",
          // },
        ],
        password: [
          { required: true, message: "请输入登录密码", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
    this.$store.commit("setSubLoading", false);
    util.removeToken();
  },
  methods: {
    submitForm() {
      this.$refs["loginForm"].validate((valid) => {
        if (valid) {
          this.$store.commit("setSubLoading", true);
          api.storeLogin(this.loginForm).then((res) => {
            util.setToken(res.data.accessToken);
            api.getLoginUser().then((res) => {
              this.$store.commit("setUser", res.data);
              this.$router.push("/dashboard");
            });
          });
        } else {
        }
      });
    },
    toRestPsd() {},
  },
};
</script>
>
<style lang="less" >
.login-page {
  height: 100vh;
  .logo {
    width: 100vw;
    height: 50vh;
    background: url("../assets/login-bgc.jpg");
    background-size: cover;
    // display: flex;
    // align-items: center;
    // justify-content: center;
    // flex-wrap: wrap;
    overflow: hidden;
    div {
      text-align: center;
      .img1 {
        // width: 134px;
        height:15vh;
        z-index: 100;
        position: relative;
        top: 70px;
      }
      .img2 {
        // width: 773px;
        height: 30vh;
        z-index: 100;
        position: relative;
        top: 30px;
      }
    }
  }
  .form {
    width: 100vw;
    position: relative;
    > .loginForm {
      position: absolute;
      left: 50%;
      top: 64px;
      transform: translateX(-50%);
      width: 368px;
      .el-form-item {
        margin-bottom: 24px;
        .el-form-item__content {
          margin-left: 0 !important;
        }
      }
      .opt {
        color: rgba(0, 0, 0, 0.65);
        display: flex;
        justify-content: space-between;
        .check {
          margin-right: 6px;
        }
        .forget {
          color: #0b4e9e;
          cursor: pointer;
        }
      }
      .submit {
        background-color: #0b4e9e;
        width: 100%;
        color: #fff;
        font-size: 16px;
      }
    }
  }
}
</style>
